package com.demo.controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;

import com.generator.tools.restful.CommonResult;
import com.demo.entity.Order;
import com.demo.service.IOrderService;
import com.generator.tools.pagehelper.CommonPage;

import java.util.List;

/**
* @author blue demon
* @date 2020/02/08
*/
@Api(tags = "")
@RestController
@RequestMapping("/order")
public class OrderController {

	@Autowired
	private IOrderService orderService;


	@ApiOperation(" 查询列表")
	@PostMapping("/selectOrderList")
	public CommonResult<?> selectOrderList(Order order,
		@RequestParam(value = "pageNum",defaultValue = "1",required = false) int pageNum,
		@RequestParam(value = "pageSize",defaultValue = "10",required = false)int pageSize){
		List<Order> orders = orderService.selectOrderList(order,pageNum,pageSize);
		return CommonResult.success(CommonPage.restPage(orders));
	}

	@ApiOperation("通过Id查询")
	@GetMapping("/selectOrderById/{id}")
	public CommonResult<?> selectOrderById(@PathVariable("id") Long id){
		return CommonResult.success(orderService.selectOrderById(id));
	}
	
	@ApiOperation("新增")
	@PostMapping("/insertOrder")
	public CommonResult<?> insertOrder(Order order){
		return CommonResult.success(orderService.insertOrder(order));
	}


	@ApiOperation("修改信息")
	@PostMapping("/updateOrder")
	public CommonResult<?> updateOrder(Order order){
		return CommonResult.success(orderService.updateOrder(order));
	}

	@ApiOperation("通过id删除")
	@PostMapping("/deleteOrderById/{id}")
	public CommonResult<?> deleteOrderById(@PathVariable("id") Long id){
		return CommonResult.success(orderService.deleteOrderById(id));
	}

	@ApiOperation("通过id批量删除")
	@PostMapping("/deleteList")
	public CommonResult<?> deleteOrderByIds(String ids){
		return CommonResult.success(orderService.deleteOrderByIds(ids));
	}
}